import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Vuex from 'vuex'
import fastclick from 'fastclick'
import './assets/js/adapter'
import './assets/css/global.less'
// 安装 图片预览插件
import VuePreview from 'vue-preview'
// 导入格式化时间的插件
import moment from 'moment'
Vue.use(Vuex)
fastclick.attach(document.body)
Vue.use(VuePreview)
// 定义全局的过滤器
Vue.filter('dateFormat', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return moment(dataStr).format(pattern)
})
Vue.filter('TimeFormat', function (valueTime) {
  if (valueTime) {
    valueTime = new Date(valueTime)
    const newData = Date.parse(new Date())
    const diffTime = Math.abs(newData - valueTime)
    if (diffTime > 7 * 24 * 3600 * 1000) {
      const date = new Date(valueTime)
      let m = date.getMonth() + 1
      m = m < 10 ? ('0' + m) : m
      let d = date.getDate()
      d = d < 10 ? ('0' + d) : d
      let h = date.getHours()
      h = h < 10 ? ('0' + h) : h
      let minute = date.getMinutes()
      minute = minute < 10 ? ('1' + minute) : minute
      return m + '-' + d + ' ' + h + ':' + minute
    } else if (diffTime < 7 * 24 * 3600 * 1000 && diffTime > 24 * 3600 * 1000) {
      // //注释("一周之内");

      // let time = newData - diffTime;
      const dayNum = Math.floor(diffTime / (24 * 60 * 60 * 1000))
      return dayNum + '天前'
    } else if (diffTime < 24 * 3600 * 1000 && diffTime > 3600 * 1000) {
      // //注释("一天之内");
      // let time = newData - diffTime;
      const dayNum = Math.floor(diffTime / (60 * 60 * 1000))
      return dayNum + '小时前'
    } else if (diffTime < 3600 * 1000 && diffTime > 0) {
      // //注释("一小时之内");
      // let time = newData - diffTime;
      const dayNum = Math.floor(diffTime / (60 * 1000))
      return dayNum + '分钟前'
    }
  }
})

Vue.http.options.root = 'http://vue.studyit.io'
// 全局设置 post 时候表单数据格式组织形式   application/x-www-form-urlencoded
Vue.http.options.emulateJSON = true
Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
